package com.dal.constant;

import com.dal.module.account.account_creator.HeiTaoAccountCreator;
import org.error.LoginErrorCode;

import com.dal.db.bean.ChannelApp;
import com.dal.module.account.account_creator.AccountCreator;
import com.dal.module.account.account_creator.LocalTestAccountCreator;
import com.sojoys.artifact.tools.ToolError;

/**
 * 账号创建器枚举
 * Created by fxf on 2017/6/26.
 */
public enum AccountCreatorEnum {

    /** 内测账号 */
	LOCAL_TEST(ChannelType.LOCAL_TEST, new LocalTestAccountCreator()),
    HEI_TAO(ChannelType.HEI_TAO, new HeiTaoAccountCreator()),
    ;
    String channelTag;
    AccountCreator accountCreator;

    AccountCreatorEnum(String channelTag, AccountCreator accountCreator) {
        this.channelTag = channelTag;
        this.accountCreator = accountCreator;
    }

    /**
     * 获取创建者
     * @param channelTag 创建者类型
     * @return 创建者
     */
    public static AccountCreator getAccountCreator(ChannelApp channelApp){
        for (AccountCreatorEnum accountCreatorEnum : values()) {
            if (accountCreatorEnum.channelTag.equals(channelApp.getChannelPkChannelId().getTag())) {
                return accountCreatorEnum.accountCreator;
            }
        }
        ToolError.isAndTrue(LoginErrorCode.CREATOR_TYPE_ERR,true);
        return null;
    }
}
